const fs = require('fs')
const path = require('path')
const http = require('http')

let pathurl = path.join(__dirname, '../files/chengji-ok.txt')


/* let app = http.createServer( async (req,res)=> {
    res.setHeader("Content-Type", 'text/html;charset=utf-8') 
   let data = await readFileFn()
   res.write(data)
        res.end()
}) */

/* let app = http.createServer( async (req,res)=> {
    res.setHeader("Content-Type", 'text/html;charset=utf-8') 
    let data = await readFileFn()
    res.write(data)
    res.end()
}) */

let app = http.createServer( async (req,res)=> {
    res.setHeader("Content-Type", 'text/html;charset=utf-8') 
    let data = await readFileFn()
    res.write(data)
    res.end()
})

app.listen(3000, () => {
    console.log('3000 run');
})

let readFileFn = ()=> {
    return new Promise((resolve,reject)=> {
        fs.readFile(pathurl,'utf8',(err,data)=> {
            if(err) {
                reject(err)
            } else {
                resolve(data)
            }
        })

    })
}